<?php
namespace app\common\model\project_model;

use app\common\helper\Obj2Array;
use think\Model;

class SystemMusicModel extends Model {

    const STATUS_LOCK = 0;
    const STATUS_OK = 1;

    const TYPE_SYSTEM = 2; // 录入系统的音乐
    const TYPE_OUT = 1; // 从外网获取播放地址

    protected $table = 'ph_system_music';

    public static function statusList() {
        return [
            self::STATUS_OK => '启用',
            self::STATUS_LOCK => '锁定',
        ];
    }

    public static function typeList() {
        return [
            self::TYPE_OUT => '外链播放',
            self::TYPE_SYSTEM => '系统音乐',
        ];
    }

    /**
     * 音乐list
     *
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function musicList() {
        $musicM = new self();
        $musicD = $musicM->field('id, title, mp3_url')->where(['status' => self::STATUS_OK, 'type' => self::TYPE_SYSTEM])->select();
        if (empty($musicD)) {
            return [];
        }
        return Obj2Array::resObject2Array($musicD);
    }

    public static function musicList2() {
        $musicM = new self();
        $musicD = $musicM->field(['music_id'=> 'id', 'title', 'mp3_url'])->where(['status' => self::STATUS_OK, 'type' => self::TYPE_SYSTEM])->select();
        if (empty($musicD)) {
            return [];
        }
        return Obj2Array::resObject2Array($musicD);
    }

}